package org.young.admin.controller.sys;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.young.admin.model.LoginModel;
import org.young.admin.service.sys.IUserService;
import org.young.common.bean.Result;
import org.young.common.utils.PasswordUtil;
import org.young.rbac.dao.model.SysUser;

import java.util.Map;

/**
 * @author lmhd-emp
 * @date 2021/5/11 11:48
 * @description:
 */
@Api(tags = "用户登录")
@RestController
@RequestMapping(value = "/sys")
public class LoginController {

	@Autowired
	IUserService userService;

	@ApiOperation(value = "登录接口")
	@PostMapping(value = "/login")
	public Object login(@RequestBody LoginModel loginModel) {
		String username = loginModel.getUsername();
		String password = loginModel.getPassword();
		// 校验用户名 是否有效
		SysUser sysUser = userService.checkUserIsEffective(username, password);
		Map map = userService.setUserInfoToCache(sysUser);
		return Result.success(map);
	}

	public static void main(String[] args) {
		String bqc = PasswordUtil.encrypt("bqc", "123456", "12345678");
		System.out.println(bqc);
	}
}
